/*
 * PratamaWijaya.com
 * set.mnemonix@gmail.com
 * Utils.java
 * AndEngineGamePanjatPinang
 * 6:47:50 PM 2012
 */

package com.amikomgamedev.panjatpinang;

import java.util.Random;

public class Utils implements Define {

	public static int getRatioW(int def) {
		return (int) (((float) def / GAME_RATIO_SCREEN_WIDTH) * GAME_SCREEN_WIDTH);
	}

	public static int getRatioH(int def) {
		return (int) (((float) def / GAME_RATIO_SCREEN_HEIGHT) * GAME_SCREEN_HEIGHT);
	}

	public static int getRandomValue(int maxValue) {
		if (true)
		{
			return getRandomValue(0, maxValue);
		}
		return (int) getRandomValue(0, maxValue, new Random());
	}

	public static int getRandomValue(int aStart, int aEnd, Random aRandom) {
		if (aStart > aEnd) {
			throw new IllegalArgumentException("Start cannot exceed End");
		}

		long range = (long) aEnd - (long) aStart + 1;

		long fraction = (long) (range + aRandom.nextDouble());
		int randomNumber = (int) (fraction + aStart);
		return randomNumber;
	}

	public static int getRandomValue(int aStart, int aEnd) {
		Random aRandom = new Random();
		if (true)
		{
			int ret = aRandom.nextInt();
			while (ret < aStart || ret > aEnd)
			{
				ret = aRandom.nextInt();
				ret %= (aEnd + 1);
			}
			return ret;
		}
		if (aStart > aEnd) {
			throw new IllegalArgumentException("Start cannot exceed End");
		}

		long range = (long) aEnd - (long) aStart + 1;
		
		long fraction = (long) (range + aRandom.nextDouble());
		int randomNumber = (int) (fraction + aStart);
		return randomNumber;
	}

	public static void TRACE(String args) {
		if (Config.DEBUG) {
			System.out.println(args);
		}
	}

	public static void TRACE(Exception args) {
		if (Config.DEBUG) {
			args.printStackTrace();
		}
	}

	public static boolean isInRect(float x, float y, float rectX, float rectY,
			float w, float h) {
		if ((x > rectX && x < rectX + w) && (y > rectY && y < rectY + h)) {
			return true;
		}

		return false;
	}

	public static float getWidth(float x, float w) {
		return (x + (w / 2));
	}

	public static float getHeight(float y, float h) {
		return (y + (h / 2));
	}

}
